//波次单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var user_name=thisform.find('input[name=user_name]').val();
		var user_phone=thisform.find('input[name=user_phone]').val();
		var is_delivery=thisform.find('input[name=is_delivery]').val();
		$('#logisticsBatchInfoDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#logisticsBatchInfoDatagrid').datagrid({
			queryParams:{
				order_no:order_no,
				user_name:user_name,
				user_phone:user_phone,
				batch_id:batch_id
			}
		});
	})
	$('#logisticsBatchInfoDatagrid').datagrid({
		url:getOrderlistUrl,
		title:'绑定订单列表',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'order_no',title:'订单编码',sortable:true},
		{field:'user_name',title:'客户姓名'},
		{field:'user_phone',title:'联系电话'},
		{field:'user_idcard',title:'身份证'},
		{field:'user_address',title:'客户详细地址'}
		]],
		queryParams:{
			batch_id:batch_id,
			page:1
		},
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
	$('#logisticsBatchAddDatagrid').datagrid({
		//url:getCollectgoodsUrl+"?randnum="+Math.floor(Math.random()*1000000),
		url:getOrderUrl,
		title:'',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'order_no',title:'订单编码',sortable:true},
		{field:'user_name',title:'收件人姓名'},
		{field:'user_phone',title:'联系电话'},
		{field:'user_idcard',title:'身份证'},
		{field:'province',title:'省',sortable:true},
		{field:'city',title:'市',sortable:true},
		{field:'area',title:'区',sortable:true},
		{field:'user_address',title:'客户详细地址'},
		{field:'platform_name',title:'订单来源'},
		{field:'company_name',title:'商户名称'},
		{field:'add_time',title:'接收时间'}
		]],
		onLoadError:function(data){
			console.log(data);
			// alert();
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
logisticsBatchInfoObj={
	bindBar:function(){//绑定订单
		var indexgoodsRow=$('#logisticsBatchAddDatagrid').datagrid('getSelections');
        if (indexgoodsRow.length>0){
        	$.messager.confirm('提示','真的要添加这'+indexgoodsRow.length+'个订单吗?',function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<indexgoodsRow.length;i++){
                		ids.push(indexgoodsRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(logisticsbatchorderaddUrl,{id:id,batch_id:batch_id},function(result){
                        if (result.status){
							$.messager.alert('提示信息',result.message,'info',function(r){
								$('#logisticsBatchAddDialog').dialog('close');
								$('#logisticsBatchInfoDatagrid').datagrid('reload'); 
								
							});
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	infoBar:function(){
		$('#logisticsBatchAddDialog').dialog('open').dialog('setTitle','订单列表');
	},
	delBar:function(){
		var Row=$('#logisticsBatchInfoDatagrid').datagrid('getSelections');
        if (Row.length>0){
        	$.messager.confirm('提示','真的要删除这'+Row.length+'个订单吗?',function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
                    $.post(delLogisticsBatchAddUrl,{id:id,batch_id:batch_id},function(result){
                        if (result.status){
							$.messager.alert('提示信息',result.message,'info',function(r){
								$('#logisticsBatchInfoDatagrid').datagrid('reload'); 
								
							});
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	printBar:function(){
		var Row=$('#logisticsBatchInfoDatagrid').datagrid('getSelections');
        if (Row.length>1){
			$.messager.alert('提示','一次只能选择一条记录','error');
		}else if(Row.length==1){
            	var id=Row[0]['id'];
				// showTab(printoutboundUrl,'打印出库单',id,2);
				var url=printoutboundUrl+"/id/"+id
				window.open(url); 
		}else{
			$.messager.alert('提示','请选择列表数据','error');
		}
	},
	showAll:function(){
		$('#logisticsBatchInfoDatagrid').datagrid({ 
			queryParams:{
				batch_id:batch_id,
				page:1
			}});
	}
}